package com.cc.infrastructure.special.impl;

import com.cc.infrastructure.special.dto.UserAllTypeDo;
import com.cc.infrastructure.special.impl.UserAllTypeDao;
import com.sccin.components.jpa.entiy.ParamConditionBO;
import com.sccin.components.jpa.entiy.type.ConditionEnum;
import com.sccin.components.query.AutoPageJpa;
import com.sccin.components.utils.auto.AutoUtil;
import com.sccin.components.utils.auto.parseParamCondition.RequirParametersAndConditions;
import org.springframework.data.domain.Page;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class UserAllTypeimpl implements UserAllTypeDao {
  @PersistenceContext
  private EntityManager entityManager;

  @Override
  public Page<UserAllTypeDo> query(String name, int pageNum, int pageSize) {
    AutoPageJpa<UserAllTypeDo> autoPageJpa = new AutoPageJpa<>(UserAllTypeDo.class);
    StringBuilder select = new StringBuilder("SELECT id,name,age,sex,height,weight,money,dashuju,picture,birth,birth_stamp,birth_time,json,description,description_text,description_tiny,other_test_by_null_string");
    StringBuilder from = new StringBuilder("FROM user_all_type");

    RequirParametersAndConditions<ParamConditionBO, Object> where = RequirParametersAndConditions.getInstance();
    where.initParamAndCondition("xxx", Condition.eq, 1).initParamAndCondition("xxx2", Condition.like, 2).initParamAndCondition("xxx3", Condition.contain, 3);
    return autoPageJpa.autopage(select, null, from, where, null, AutoUtil.initPageable(pageNum, pageSize), entityManager);
  }
}